layui.use([ 'form', 'carousel' ], function() {
	var form = layui.form;

	var carousel = layui.carousel;
	carousel.render({
		elem : '#carousel',
		width : '100%', // 设置容器宽度
		arrow : 'always' // 始终显示箭头
	});
	
	//图片退格
	$(".back").click(function(){
		$("#demo2").children().last().remove();
		var file = $("#fileupload").val();
		if (file.lastIndexOf(',')>0) {
			//找到字符串并删除
			$("#fileupload").val(file.slice(0,file.lastIndexOf(',')))
		} else {
			$("#fileupload").val("");
		}
	})
	
	form.on('submit(formDemo)', function(data) {
		$.post("HomeRotaryMapInsert.do", data.field, function(res) {
			if (res.type == 1) {
				layer.msg("保存成功");
			} else {
				layer.msg("保存失败", {
					area : [ '300px', '200px' ]
				});
			}
			setTimeout(function() {
				location.reload();
			}, 1000);
		}, "json")
		return false;
	});
});
layui.use('upload',function() {
var $ = layui.jquery, upload = layui.upload;
// 多图片上传
upload
		.render({
			elem : '#test2',
			url : 'UploadServlet.do',
			multiple : true,
			before : function(obj) {
				// 预读本地文件示例，不支持ie8
				obj
						.preview(function(index, file,
								result) {
							$('#demo2')
									.append(
											'<img src="'
													+ result
													+ '" alt="'
													+ file.name
													+ '" style="width: 200px;height: 70px;" class="layui-upload-img">')
						});
			},
			done : function(res) {
				console.log(res);
				if (res.type == 1) { // 上传成功
					var a = $("#fileupload").val();
					if (a == '') {
						$("#fileupload").val(
								res.data.data.src);
					} else {
						$("#fileupload")
								.val(
										a
												+ ","
												+ res.data.data.src);
					}
				}
			}
		});
				});